package com.dries.portal.module.friends.controller;

import com.dries.common.api.CommonResult;
import com.dries.portal.module.user.entity.UserEntity;
import com.dries.portal.module.friends.entity.Friends;
import com.dries.portal.module.friends.service.IFriendsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 好友关系关联表
 *
 * @author dries
 * @email samphsanie@gmail.com
 * @date 2020-08-17 09:59:44
 */
@RestController
@Api(tags = "好友列表", value = "FriendsController")
@RequestMapping("friends/Friends")
public class FriendsController {

    @Resource
    private IFriendsService friendsService;

    /**
     * 列表
     */
    @ApiOperation(value = "好友列表")
    @GetMapping("/list/{userId}")
    public CommonResult list(@PathVariable String userId){

        List<UserEntity> friends = friendsService.friends(userId);

        return CommonResult.success(friends);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public CommonResult info(@PathVariable("id") Integer id){
		Friends friends = friendsService.getById(id);
        return CommonResult.success();
    }

    /**
     * 添加好友
     */
    @ApiOperation(value = "添加好友")
    @PostMapping("/save")
    public CommonResult save(@RequestBody Friends friends){

		friendsService.save(friends);

        return CommonResult.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public CommonResult update(@RequestBody Friends friends){
		friendsService.updateById(friends);
        return CommonResult.success();
    }

    /**
     * 删除好友
     */
    @ApiOperation(value = "删除好友")
    @DeleteMapping("/delete")
    public CommonResult delete(@RequestBody Integer[] ids){

		friendsService.removeByIds(Arrays.asList(ids));

        return CommonResult.success();
    }

}
